package cool.mtc.base.plugin.generator.code.model.form;

import cool.mtc.base.plugin.generator.code.model.template.BaseTemplateParam;
import cool.mtc.base.plugin.generator.code.model.template.bg.*;
import cool.mtc.base.plugin.generator.code.model.template.ui.*;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

/**
 * @author 明河
 */
@Data
public class TemplateParamForm {

    // 前端代码
    private UiTemplateParam uiParam;

    // 后端代码
    private BgEntityTemplateParam entityParam;
    private BgModelTemplateParam modelParam;
    private BgDaoTemplateParam daoParam;
    private BgServiceTemplateParam serviceParam;
    private BgManagerTemplateParam managerParam;
    private BgControllerTemplateParam controllerParam;

    public List<BaseTemplateParam> handleCheckParamCorrect() {
        List<BaseTemplateParam> paramList = new ArrayList<>();

        // region 前端代码
        Optional.ofNullable(uiParam).ifPresent(param -> {
            param.handleCheckParamsCorrect();

            paramList.add(new UiModelTemplateParam(param));
            paramList.add(new UiApiTemplateParam(param));
            paramList.add(new UiComponentEditTemplateParam(param));
            paramList.add(new UiComponentOperationTemplateParam(param));
            paramList.add(new UiComponentQueryTemplateParam(param));
            paramList.add(new UiComponentTableTemplateParam(param));
            paramList.add(new UiPageTemplateParam(param));
        });
        // endregion

        // region 后端代码
        // Entity
        Optional.ofNullable(entityParam).ifPresent(param -> {
            param.handleCheckParamsCorrect();
            paramList.add(param);
        });
        // Dao
        Optional.ofNullable(daoParam).ifPresent(param -> {
            param.handleCheckParamsCorrect();
            paramList.add(param);

            BgDaoXmlTemplateParam daoXmlParam = new BgDaoXmlTemplateParam(daoParam);
            daoXmlParam.handleCheckParamsCorrect();
            paramList.add(daoXmlParam);
        });
        // Model
        Optional.ofNullable(modelParam).ifPresent(param -> {
            // form
            BgModelFormTemplateParam formParam = new BgModelFormTemplateParam(modelParam);
            formParam.handleCheckParamsCorrect();
            paramList.add(formParam);
            // query
            BgModelQueryTemplateParam queryParam = new BgModelQueryTemplateParam(modelParam);
            queryParam.handleCheckParamsCorrect();
            paramList.add(queryParam);
            // dto
            BgModelDTOTemplate dtoParam = new BgModelDTOTemplate(modelParam);
            dtoParam.handleCheckParamsCorrect();
            paramList.add(dtoParam);
            // list_dto
            BgModelDTOListTemplateParam dtoListParam = new BgModelDTOListTemplateParam(modelParam);
            dtoListParam.handleCheckParamsCorrect();
            paramList.add(dtoListParam);
        });
        // Service
        Optional.ofNullable(serviceParam).ifPresent(param -> {
            param.handleCheckParamsCorrect();
            paramList.add(param);

            // Service Impl
            BgServiceImplTemplateParam implParam = new BgServiceImplTemplateParam(param);
            implParam.handleCheckParamsCorrect();
            paramList.add(implParam);
        });
        // Manager
        Optional.ofNullable(managerParam).ifPresent(param -> {
            param.handleCheckParamsCorrect();
            paramList.add(param);

            // Manager Impl
            BgManagerTemplateParam implParam = new BgManagerImplTemplateParam(param);
            implParam.handleCheckParamsCorrect();
            paramList.add(implParam);
        });
        // Controller
        Optional.ofNullable(controllerParam).ifPresent(param -> {
            param.handleCheckParamsCorrect();
            paramList.add(param);
        });
        // endregion

        return paramList;
    }
}
